rm(list = ls())
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#install.packages("pxweb")
library(pxweb)
## Warning: package 'pxweb' was built under R version 4.1.3
## pxweb 0.13.1: R tools for the PX-WEB API.
## https://github.com/ropengov/pxweb
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.1.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(corrr)
## Warning: package 'corrr' was built under R version 4.1.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.1.2
library(stargazer)
## Warning: package 'stargazer' was built under R version 4.1.2
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
#install.packages("plotly")
library(plotly)
## Warning: package 'plotly' was built under R version 4.1.3
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
#install.packages("ggthemes")
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 4.1.3
#install.packages("extrafont")
library(extrafont)
## Warning: package 'extrafont' was built under R version 4.1.3
## Registering fonts with R
library(stringr)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
We start by importing the data set. Creating the data set is covered in a separate .r file. Thereafter, we wish to explore the data.
CPI_interest<-read.csv("CPI_interest.csv")
CPI_interest %>%
ggplot(aes(x = KPI, y = inlåningsräntor, fill = avtal)) +
geom_point(shape = 21) +
labs(title = "Inflation mot räntor", x = "KPI", y = "Inlåningsräntor") +
scale_fill_brewer(palette = "Set2", name = "Avtal") +
theme_fivethirtyeight() +
theme(axis.title = element_text(), legend.box.background = element_rect(size = 0.8))
## Warning: Removed 334 rows containing missing values (geom_point).
Thereafter, we will gain some insight into the change over time.
p = CPI_interest %>%
ggplot(aes(x = KPI, y = inlåningsräntor, fill = avtal)) +
geom_jitter(shape = 21, size = 2, aes(frame = year, ids = inlåningsräntor)) +
labs(title = "Inflation mot räntor", x = "KPI", y = "Inlåningsräntor", caption = "Nya och omförhandlade avtal började mätas i September 2005") +
scale_fill_brewer(palette = "Set2", name = "Avtal")
## Warning: Ignoring unknown aesthetics: frame, ids
fig = ggplotly(p) %>%
animation_opts(
frame = 800, transition = 400, redraw = TRUE, easing = "linear", mode = "next"
) %>%
animation_button(
x = 1, xanchor = "right", y = 0, yanchor = "bottom"
) %>%
animation_slider(
currentvalue = list(prefix = "År: ", font = list(color="grey"))
) %>%
animation_opts(1000, redraw = FALSE)
fig
# make a correlation matrix
correlations <- CPI_interest %>%
select_if(is.numeric) %>%
correlate()
##
## Correlation method: 'pearson'
## Missing treated using: 'pairwise.complete.obs'
# make some regressions, preferably with some control variables but I don't have that yet
reg1 <- lm(data = CPI_interest, inlåningsräntor ~ KPI)
stargazer(reg1, type = "text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## inlåningsräntor
## -----------------------------------------------
## KPI 0.589***
## (0.033)
##
## Constant 0.183**
## (0.080)
##
## -----------------------------------------------
## Observations 468
## R2 0.403
## Adjusted R2 0.401
## Residual Std. Error 1.313 (df = 466)
## F Statistic 314.228*** (df = 1; 466)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01